package com.ysx.server.controller;

import cn.hutool.db.sql.Order;
import com.ysx.server.pojo.dto.OrderStatusDTO;
import com.ysx.server.pojo.entity.Orders;
import com.ysx.server.pojo.vo.OrdersVO;
import com.ysx.server.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 根据用户id查询订单信息
     * @param userId
     * @return
     */
    @GetMapping("/getUserOrder/{userId}")
    public List<OrdersVO> getUserOrder(@PathVariable Long userId) {
        if(userId==null||userId<=0)
            return null;
        List<OrdersVO> userOrder = orderService.getUserOrder(userId);
        log.info("用户id:{} 查询到的订单信息:{}",userId,userOrder);
        return userOrder;
    }

    /**
     * 根据用户id查询订单信息
     * @param userId
     * @return
     */
    @GetMapping("/getSellOrder/{userId}")
    public List<OrdersVO> getSellOrder(@PathVariable Long userId) {
        if(userId==null||userId<=0)
            return null;
        List<OrdersVO> sellOrder = orderService.getSellOrder(userId);
        log.info("卖家id:{} 查询到的订单信息:{}",userId,sellOrder);
        return sellOrder;
    }

    /**
     * 根据订单id查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public OrdersVO getDetail(@PathVariable Long id){
        log.info("订单id:{}",id);
        OrdersVO ordersVO = orderService.getDeatil(id);
        log.info("订单详情:{}",ordersVO);
        return ordersVO;
    }

    /**
     * 更新订单状态
     * @param orderStatusDTO
     * @return
     */
    @PostMapping("/status")
    public boolean updateStatus(@RequestBody OrderStatusDTO orderStatusDTO){
        log.info("订单状态更新参数:{}",orderStatusDTO);
        boolean flag = orderService.updateStatus(orderStatusDTO);
        log.info("订单状态更新结果:{}",flag);
        return flag;
    }
}
